{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "69b55e34-60c0-4bce-a6fd-cb7c1b335010",
   "metadata": {},
   "source": [
    "### 读"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a0b491d1-dcf5-47a9-8443-16c8458113b6",
   "metadata": {},
   "source": [
    "#### 对比点线面的geometry"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4cdc3852-3b35-41fd-b806-30a4cac4e439",
   "metadata": {},
   "source": [
    "##### 导入包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "17b006e1-33a6-4223-9217-de2993ab9798",
   "metadata": {},
   "outputs": [],
   "source": [
    "import geopandas as gpd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1ee4551c-7649-4257-8806-16f25f3f2c0b",
   "metadata": {},
   "source": [
    "##### 点"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "d59e0548-b79e-4104-86d0-79a26a71856d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>geometry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>POINT Z (114.32328 30.58035 0)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                         geometry\n",
       "0  POINT Z (114.32328 30.58035 0)"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "point = r'data\\point.json'\n",
    "point_gdf = gpd.read_file(point)\n",
    "point_gdf"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4a586085-7d23-4a34-ae20-14d7c978377f",
   "metadata": {},
   "source": [
    "##### 线"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "a08559d9-be0b-48b9-9ae7-b0b539be1d5f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>geometry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>LINESTRING Z (114.32292 30.57889 0, 114.32716 ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            geometry\n",
       "0  LINESTRING Z (114.32292 30.57889 0, 114.32716 ..."
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "line = r'data\\line.json'\n",
    "lines_gdf = gpd.read_file(line)\n",
    "lines_gdf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "09de701f-afee-461a-b50f-6460cd8e0970",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "坐标系信息: EPSG:4979\n"
     ]
    }
   ],
   "source": [
    "print(\"坐标系信息:\", lines_gdf.crs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "c9c5ab06-bd85-4986-aea8-92ca2d7bb5ea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "几何对象类型: <class 'shapely.geometry.linestring.LineString'>\n",
      "边界框范围: (114.32291507720947, 30.573715834861623, 114.334716796875, 30.585058532281685)\n",
      "长度: 0.024150253070288525\n",
      "[(114.32291507720947, 30.578888565037637, 0.0), (114.32716369628906, 30.573715834861623, 0.0), (114.334716796875, 30.57737372262836, 0.0), (114.32991027832031, 30.585058532281685, 0.0)]\n"
     ]
    }
   ],
   "source": [
    "line_geometry = lines_gdf.geometry[0]\n",
    "print(\"几何对象类型:\", type(line_geometry))\n",
    "print(\"边界框范围:\", line_geometry.bounds)\n",
    "print(\"长度:\", line_geometry.length)\n",
    "coordinates = list(line_geometry.coords)\n",
    "print(coordinates)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8bfe26a8-c676-4725-8592-2d0c7c420375",
   "metadata": {},
   "source": [
    "##### 多边形"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "7f1a06e5-d3fa-4fbd-b3b7-ee252a4fc153",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>geometry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>POLYGON Z ((114.32292 30.57889 0, 114.32716 30...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            geometry\n",
       "0  POLYGON Z ((114.32292 30.57889 0, 114.32716 30..."
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "polygon = r'data\\polygon.json'\n",
    "polygon_gdf = gpd.read_file(polygon)\n",
    "polygon_gdf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "46b73aab-dad0-4964-80ae-738e94eeb9e6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "坐标系信息: EPSG:4979\n",
      "几何对象类型: <class 'shapely.geometry.polygon.Polygon'>\n",
      "边界框范围: (114.32291507720947, 30.573715834861623, 114.334716796875, 30.585058532281685)\n",
      "面积: 6.901198707198663e-05\n",
      "周长: 0.03347770365304283\n",
      "多边形边界坐标:\n",
      "(114.32291507720947, 30.578888565037637, 0.0)\n",
      "(114.32716369628906, 30.573715834861623, 0.0)\n",
      "(114.334716796875, 30.57737372262836, 0.0)\n",
      "(114.32991027832031, 30.585058532281685, 0.0)\n",
      "(114.32291507720947, 30.578888565037637, 0.0)\n"
     ]
    }
   ],
   "source": [
    "polygon_geometry = polygon_gdf.geometry[0]\n",
    "print(\"坐标系信息:\", polygon_gdf.crs)\n",
    "print(\"几何对象类型:\", type(polygon_geometry))\n",
    "print(\"边界框范围:\", polygon_geometry.bounds)\n",
    "print(\"面积:\", polygon_geometry.area)\n",
    "print(\"周长:\", polygon_geometry.length)\n",
    "exterior_coords = polygon_geometry.exterior.coords\n",
    "print(\"多边形边界坐标:\")\n",
    "for coord in exterior_coords:\n",
    "    print(coord)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0a3850bd-e643-41b5-b0f6-1478f423cdfe",
   "metadata": {},
   "source": [
    "##### 多个多边形"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "5b45ec33-5f44-4327-a9ef-36882ce9f4ed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>geometry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>MULTIPOLYGON Z (((114.32859 30.58094 0, 114.32...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            geometry\n",
       "0  MULTIPOLYGON Z (((114.32859 30.58094 0, 114.32..."
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "multipolygon = r'data\\multipolygon.json'\n",
    "multipolygon_gdf = gpd.read_file(multipolygon)\n",
    "multipolygon_gdf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "d93976e6-6d18-43ec-9c5a-a725ff86fd0b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "坐标系信息: EPSG:4979\n",
      "几何对象类型: <class 'shapely.geometry.multipolygon.MultiPolygon'>\n",
      "边界框范围: (114.32820171117783, 30.580521150710283, 114.32971715927124, 30.581802722749583)\n"
     ]
    }
   ],
   "source": [
    "multipolygon_geometry = multipolygon_gdf.geometry[0]\n",
    "print(\"坐标系信息:\", multipolygon_gdf.crs)\n",
    "print(\"几何对象类型:\", type(multipolygon_geometry))\n",
    "print(\"边界框范围:\", multipolygon_geometry.bounds)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "26719a6b-b5ab-40d0-ae03-0bff2121c47d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第1个Polygon的外环边界坐标:\n",
      "(114.32859063148499, 30.580943724984383, 0.0)\n",
      "(114.32971715927124, 30.580897542093247, 0.0)\n",
      "(114.32917267084122, 30.58141248008457, 0.0)\n",
      "(114.32859063148499, 30.580943724984383, 0.0)\n",
      "第1个Polygon的面积: 2.7747295276732283e-07\n",
      "第1个Polygon的周长: 0.0026242223551242085\n",
      "--------------------------------------------------\n",
      "第2个Polygon的外环边界坐标:\n",
      "(114.32831168174744, 30.58134320607455, 0.0)\n",
      "(114.32840019464493, 30.581250840650867, 0.0)\n",
      "(114.32893931865692, 30.58171035776365, 0.0)\n",
      "(114.32882398366928, 30.581802722749583, 0.0)\n",
      "(114.32831168174744, 30.58134320607455, 0.0)\n",
      "第2个Polygon的面积: 9.539335936208511e-08\n",
      "第2个Polygon的周长: 0.0016722691639380412\n",
      "--------------------------------------------------\n",
      "第3个Polygon的外环边界坐标:\n",
      "(114.32827681303023, 30.580521150710283, 0.0)\n",
      "(114.32854771614075, 30.580752065842397, 0.0)\n",
      "(114.32842701673508, 30.580874450639435, 0.0)\n",
      "(114.328236579895, 30.580858286618497, 0.0)\n",
      "(114.32820975780487, 30.58079132136017, 0.0)\n",
      "(114.32820171117783, 30.580687409660836, 0.0)\n",
      "(114.32822316884995, 30.580592734460055, 0.0)\n",
      "(114.32827681303023, 30.580521150710283, 0.0)\n",
      "第3个Polygon的面积: 7.51503087361754e-08\n",
      "第3个Polygon的周长: 0.0010818659671624224\n",
      "--------------------------------------------------\n"
     ]
    }
   ],
   "source": [
    "polygons_in_multi = multipolygon_geometry.geoms\n",
    "for i, polygon in enumerate(polygons_in_multi):\n",
    "    print(f\"第{i + 1}个Polygon的外环边界坐标:\")\n",
    "    exterior_coords = polygon.exterior.coords\n",
    "    for coord in exterior_coords:\n",
    "        print(coord)\n",
    "    interiors_list = polygon.interiors\n",
    "    for j, interior in enumerate(interiors_list):\n",
    "        print(f\"第{i + 1}个Polygon的第{j + 1}个内环边界坐标:\")\n",
    "        for coord in interior.coords:\n",
    "            print(coord)\n",
    "    print(f\"第{i + 1}个Polygon的面积:\", polygon.area)\n",
    "    print(f\"第{i + 1}个Polygon的周长:\", polygon.length)\n",
    "    print(10 * \"-----\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
